package com.itheima.mobilesafe69.activity;

import com.itheima.mobilesafe69.R;
import com.itheima.mobilesafe69.utils.ConstantValue;
import com.itheima.mobilesafe69.utils.PrefUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class MobileSafeActivity extends Activity {
	private TextView tv_safe_number;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		boolean is_setup_over = PrefUtils.getBoolean(this, ConstantValue.SETUP_OVER, false);
		if(is_setup_over){
			//如果设置完成,则停留在此界面,展示设置完成相关的布局结构
			setContentView(R.layout.activity_mobile_safe);
			
			initUI();
		}else{
			//如果设置没有完成,则跳转到第一个设置界面,让用户去做相应设置
			startActivity(new Intent(this,Setup1Activity.class));
			finish();
		}
	}

	private void initUI() {
		//从sp中获取存储的联系人号码,将其显示在控件上
		tv_safe_number = (TextView) findViewById(R.id.tv_safe_number);
		String phone = PrefUtils.getString(this, ConstantValue.CONTACT_PHONE, "");
		tv_safe_number.setText(phone);
		
		//让TextView具备可点击的操作,设置一个点击事件(TextView ImageView默认没有点击事件)(Button默认具备点击事件)
		TextView tv_reset_setup = (TextView) findViewById(R.id.tv_reset_setup);
		tv_reset_setup.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(getApplicationContext(),Setup1Activity.class));
				finish();
			}
		});
	}
}
